{extend name="ashippingguide/Public/base" /}
{block name="container"}
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<div class="page-heade">
    <h2 class="title_color text-center">导购劳动合同管理</h2>
</div>
<form action="" class="form-inline" id="form1" method="post">
    <table class="table table-bordered bud_hei">
        <tr>
            <td colspan="9"><a href="javascript:;" class="btn btn-sm btn-primary" id="addnewht">添加合同</a><span
                    class="lr_5"></span><a href="{:url('ashippingguide/labourContractAnalysis')}" class="btn btn-sm btn-info">劳动合同分析</a><span
                    class="lr_5"></span><a href="{:url('ashippingguide/labourContractAnalysisTmp')}" class="btn btn-sm btn-info">不需要签劳动合同的导购人员</a><span
                    class="lr_5"></span><a href="{:url('ashippingguide/labourimport')}"
                                           class="btn btn-sm btn-info J_menuItem">劳动合同导入</a><input type="hidden" name="a_endDate" id="date" value=""><span class="lr_5 colorRed" style="float: right;" onclick="$('#date').val(1);$('#form1').submit();">注：未来两个月内即将到期劳动合同(请点击)。</span>
            </td>
        </tr>
        <tr>
            <td>模糊查询：</td>
            <td>索引：</td>
            <td><input type="text" class="form-control" name="a_indexes"
                       value="<?php if(isset($where['a_indexes'])) echo $where['a_indexes']; ?>"></td>
            <td>甲方：</td>
            <td><input type="text" class="form-control" name="a_APartyName"
                       value="<?php if(isset($where['a_APartyName'])) echo $where['a_APartyName']; ?>"></td>
            <td>乙方：</td>
            <td><input type="text" class="form-control" name="a_BPartyName"
                       value="<?php if(isset($where['a_BPartyName'])) echo $where['a_BPartyName']; ?>"></td>
            <td>网点：</td>
            <td><input type="text" class="form-control" name="c_title"
                       value="<?php if(isset($where['c_title'])) echo $where['c_title']; ?>"></td>
        </tr>
        <tr>
            <td colspan="9" class="text-center">
                <button class="btn-sm btn-info btn" type="submit">查询</button>
                <span class="lr_5"></span>
                <button class="btn-sm btn-info btn" type="submit" id="reset">清空查询条件</button>
                <span class="lr_5"></span><a href="javascript:;" onclick='window.open("/index/ashippingguide/exportLabourContract","_self")' class="btn btn-info btn-sm">导出Excel</a>
            </td>
        </tr>
    </table>
    <table class="table table-striped table-bordered table-hover bud_hei text-center">
        <tr class="info">
            <th class="text-center">No.</th>
            <th class="text-center">索引</th>
            <th class="text-center">乙方姓名</th>
            <th class="text-center">岗位类型</th>
            <th class="text-center">甲方名称</th>
            <th class="text-center">乙方所属网点名称</th>
            <th class="text-center">合同起始日</th>
            <th class="text-center">合同到期日</th>
            <th class="text-center">签署<br>次数</th>
            <th class="text-center">已返回<br>合同</th>
            <th class="text-center">状态</th>
            <th class="text-center">操作</th>
        </tr>
        <tbody style="border: 0">
        {volist name="data" id="list"}
        <tr>
            <td>{$i}</td>
            <td>{$list.indexes}</td>
            <td>{$list.BPartyName}</td>
            <td>{$list.postType}</td>
            <td>{$list.APartyName}</td>
            <td class="text-left"><a href="/index/net/view/?id={$list.mainNet_id}"
                                     class="J_menuItem">{$list.mainNet}</a></td>
            <td>{$list.signDate}</td>
            <td>{$list.endDate}</td>
            <td>{$list.signNum}</td>
            <td>{$list.returnContract}</td>
            <td>{$list.state}</td>
            <td><a href="javascript:;" onclick="edit({$list.id})" class="modify">修改</a>&nbsp;<a href="javascript:;"
                                                                                                onclick="del({$list.id})"
                                                                                                class="delthis">删除</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <h5 class="text-center" style="font-size: 13px;font-weight: 500">
        总共有{$count}条记录，第{$page}/{$maxpage}页,当前页<input id="page" name="pages" type="text" style="width: 40px" value=""/>
        <button id="gopage" type="submit">Go</button>&nbsp;&nbsp;<button id="fistpage" type="submit"
                                                                         onclick="$('#form1').find('input').val('');">首页
    </button>&nbsp;&nbsp;
        每页显示
        <select id="pagesize" name="limts">
            <option value='10'>10条</option>
            <option value='15'>15条</option>
            <option value='20'>20条</option>

        </select>
        <script>
            $('#pagesize').val("{$limit}");
        </script>
    </h5>
</form>
<div id="addlaborcontractDiv" class="ibox-content" style="display: none">
    <form action="{:url('ashippingguide/labourAdd')}" class="form-inline" id="form2" method="post">
        <input type="hidden" value="" name="id" id="id">
        <table class="table table-bordered">
            <tr>
                <td style="width: 140px" class="text-center">索引<span class="colorRed">*</span></td>
                <td colspan="3"><input type="text" class="form-control validate[required]" name="indexes" id="indexes"
                                       value=""></td>
            </tr>
            <tr>
                <td class="text-center">合同名称<span class="colorRed">*</span></td>
                <td colspan="3"><input type="text" class="form-control validate[required]" name="contractName"
                                       id="contractName" value=""></td>
            </tr>
            <tr>
                <td class="text-center">甲方名称<span class="colorRed">*</span></td>
                <td>
                    <select name="APartyName" id="APartyName" class="form-control select validate[required]">
                        <option value="">请选择</option>
                        <option value="广州销路通软件公司">广州销路通软件公司</option>
                        <option value="A公司">A公司</option>
                        <option value="测试甲方名称">测试甲方名称</option>
                        <option value="B公司">B公司</option>
                    </select>
                </td>
                <td class="text-center">乙方名称<span class="colorRed">*</span></td>
                <td>
                    <div class="col-xs-6">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="" name="BPartyName"
                                   id="BPartyName"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="BPartyName_id" id="BPartyName_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectBPartyName" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="text-center">合同起始日<span class="colorRed">*</span></td>
                <td><input type="text" id="signDate" class="form-control layer-date validate[required,custom[date]]"
                           style="min-width:160px;width:160px;display: inline-block;" name="signDate" value=""></td>
                <td class="text-center">合同到期日<span class="colorRed">*</span></td>
                <td><input type="text" id="endDate" class="form-control layer-date validate[required,custom[date]]"
                           style="min-width:160px;width:160px;display: inline-block;" name="endDate" value=""></td>
            </tr>
            <tr>
                <td class="text-center">签署次数</td>
                <td><input type="text" class="form-control" name="signNum" value="" id="signNum"
                           style="width: 40px;background-color: #efffff;"><a href="javascript:alert('不知道啥意思？');">查询</a><span
                        class="font-bold">(请点击查询按钮获取本次签署次数)</span></td>
                <td class="text-center">已返回合同</td>
                <td>
                    <label for="returnContract0">
                        <input type="radio" name="returnContract" id="returnContract0" value="0" checked>×
                    </label>
                    <label for="returnContract1">
                        <input type="radio" name="returnContract" id="returnContract1" value="1">√
                    </label>
                </td>
            </tr>
            <tr>
                <td class="text-center">工作地点</td>
                <td><input type="text" class="form-control" name="workAddress" value="" id="workAddress"></td>
                <td class="text-center">合同性质</td>
                <td>
                    <select name="contractType" id="contractType" class="form-control select">
                        <option value="0">请选择</option>
                        <option value="1">8小时工作制</option>
                        <option value="2">不定时工作制</option>
                        <option value="3">综合工时</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="text-center">合同通讯地址</td>
                <td colspan="3"><input type="text" class="form-control" id="address" name="address" value=""
                                       style="width: 60%"></td>
            </tr>
            <tr>
                <td class="text-center">备注</td>
                <td colspan="3"><textarea name="des" id="des" style="width: 70%;height: 60px;resize: none;"
                                          class="form-control"></textarea></td>
            </tr>
        </table>
    </form>
</div>
<script>
    //日期范围限制
    var start = {
        elem: '#signDate',
        format: 'YYYY/MM/DD',
        min: '1970-01-01 23:59:59', //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#endDate',
        format: 'YYYY/MM/DD',
        min: '1970-01-01 23:59:59',
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);


    $('#form2').validationEngine('attach', {
        promptPosition: 'bottomRight'
    });
    //销售人员搜索自动补全
    $("#BPartyName").bsSuggest({
        url: "/index.php/index/ashippingguide/BPartyNameTreeJson",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias: {title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "name",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log(keyword);
        $('#BPartyName').val(keyword.key);
        $('#BPartyName_id').val(keyword.id);
    });
    //弹出选择销售人树
    $('#selectBPartyName').click(function () {
        layer.open({
            type: 2,
            area: ['60%', '60%'],
            title: '销售人',
            maxmin: true,
            content: '/index.php/index/ashippingguide/BPartyNameTreeP',
            btn: ['确定', '关闭'],
            btnAlign: 'c',
            yes: function (i, o) {
                var id = $(o).find('iframe').contents().find('#renyuan').val()
                var name = $(o).find('iframe').contents().find('#renyuanname').val()
                if (id) {
                    $('#BPartyName').val(name);
                    $('#BPartyName_id').val(id);
                }
                layer.close(i)
            }
        });
        return false
    });

    $("#addnewht").click(function () {
        layer.open({
            type: 1,
            title: '添加新合同',
            area: ['900px', '450px'],
            fixed: false, //不固定
            maxmin: true,
            btn: ["提交", "返回"],
            content: $('#addlaborcontractDiv'),
            yes: function (i, o) {
                if($('#form2').validationEngine('validate')){
                    $('#form2').submit();
                }
                // var param = $('#form1').serialize()
                // $.post('/index/workflowdb/ysfy_cg.html', param, function (data) {
                //     if (data.success) {
                //         swal({title: data.msg}, function () {
                //             layer.close(i)
                //             location.reload()
                //         })
                //     } else {
                //         swal(data.msg)
                //     }
                // }, 'json')
            }
        });


    })
    /*职员年假重新计算*/
    // $("#staffnjcount").click(function(){
    //     swal({
    //             title: "",
    //             text: "确定重新计算年假，将所有年假已支取天数将归零吗？",
    //             type: "warning",
    //             showCancelButton: true,
    //             confirmButtonColor: "#DD6B55",
    //             confirmButtonText: "确定！",
    //             closeOnConfirm: false
    //         },
    //         function(){
    //             swal("", "", "success");
    //         });
    // })
    $(document).ready(function () {
        $('#reset').on('click', function () {
            $("#form1 input").each(function () {
                $(this).val('');
            });
            $("#form1 select").each(function () {
                $(this).val('');
            });
            $('#form1').submit()
            return false
        })


    })

    /*返回*/
    // $('#fanhui').on('click',function () {
    //     // parent.layer.close(parent.layer.getFrameIndex(window.name))
    //     location.reload();
    //     return false
    // })
    /*修改*/
    function edit(id) {
        $.get("{:url('ashippingguide/labourEdit')}", {id: id}, function (e) {
            $('#id').val(e.id);
            $('#indexes').val(e.indexes);
            $('#contractName').val(e.contractName);
            $('#APartyName').val(e.APartyName);
            $('#BPartyName').val(e.BPartyName);
            $('#BPartyName_id').val(e.BPartyName_id);
            $('#signDate').val(e.signDate);
            $('#endDate').val(e.endDate);
            $('#signNum').val(e.signNum);
            $('#returnContract').val(e.returnContract);
            $('#workAddress').val(e.workAddress);
            $('#contractType').val(e.contractType);
            $('#address').val(e.address);
            $('#des').val(e.des);
            layer.open({
                type: 1,
                title: '添加新合同',
                area: ['900px', '450px'],
                fixed: false, //不固定
                maxmin: true,
                btn: ["提交", "返回"],
                content: $('#addlaborcontractDiv'),
                yes: function (i, o) {
                    if($('#form2').validationEngine('validate')){
                        $('#form2').submit();
                    }
                }
            });
        }, 'json');
    }

    //     $(document).on("click",".modify",function(){
    //         layer.open({
    //             type: 1,
    //             title: '修改职员年假',
    //             area: ['900px', '600px'],
    //             fixed: false, //不固定
    //             maxmin: true,
    //             content: $('#addtrainplanDiv')
    //             /*   yes: function (i, o) {
    //                    var param = $('#form1').serialize()
    //                $.post('/index/workflowdb/ysfy_cg.html', param, function (data) {
    //                    if (data.success) {
    //                        swal({title: data.msg}, function () {
    //                            layer.close(i)
    //                            location.reload()
    //                        })
    //                    } else {
    //                        swal(data.msg)
    //                    }
    //                }, 'json')
    //            }
    // */
    //         });
    //
    //     })
    /*删除*/

    function del(id) {
        swal({
                title: "确定此操作吗？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定！",
                closeOnConfirm: false
            },
            function () {
                // swal("", "", "success");
                $.get("{:url('ashippingguide/labourDel')}", {id: id}, function (e) {
                    if(e.success){
                        location.reload();
                    }
                }, 'json');
            });
    }

    // $(document).on("click",".delthis",function(){
    //
    // })

</script>
{/block}